<div class="content-form">
    <h2><?php echo $this->titulo; ?></h2>

    <?php
    $readonly = $this->data['VND_ID'] > 0 ? 'readonly=""' : '';
    $disabled = $this->data['VND_ID'] > 0 ? 'disabled=""' : '';
    ?>

    <?php if ($this->data['VND_ID'] <= 0) { ?>
        <div id="content-form">
            <form id="form_list" name="form_list" method="post">
                <div class="row">
                    <div class="col-md-4">
                        <dt><label>Produto</label></dt>   
                        <dd>
                            <input type="hidden" id="PRO_ID" name="PRO_ID" value="" class="find_id">
                            <input type="text" id="PRO_NOM" name="PRO_NOM" class="form-control w-auto find" value="">
                        </dd>
                    </div>
                    <div class="col-md-2">
                        <dt><label>R$(Unit)</label></dt>   
                        <dd>
                            <input type="text" id="PRO_VLRVND" name="PRO_VLRVND" class="form-control w-auto find_prc" value="" readonly="">
                        </dd>
                    </div>
                    <div class="col-md-1">
                        <dt><label>Qtd</label></dt>   
                        <dd>
                            <input type="text" id="PRO_QTD" name="PRO_QTD" class="form-control w-auto numero" value="" maxlength="5">
                        </dd>
                    </div>
                    <div class="col-md-2">
                        <dt><label>Preço</label></dt>   
                        <dd>
                            <input type="text" id="PRO_VLRVNDTOT" name="PRO_VLRVNDTOT" class="form-control w-auto" value="" readonly="">
                        </dd>
                    </div>
                    <div class="col-md-1 row-btn">
                        <button type="button" class="btn btn-primary" id="lancar">
                            <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>
                            Lançar
                        </button>
                    </div>
                </div>

                </dd>
            </form>
        </div>
    <?php } ?>
</div>

<form id="form_edt" name="form_edt" enctype="application/x-www-form-urlencoded" action="" method="post" novalidate="novalidate">
    <div class="table-responsive">

        <div class="form-group">
            <table id="tlist" class="table table-striped table-hover">
                <thead>
                    <tr>
                        <th>Produto</th>
                        <th>Qtd / R$(Unit)</th>
                        <th>Preço</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody id="lista">
                    <?php
                    if (isset($this->prod))
                        foreach ($this->prod as $pro) {
                            ?>
                            <tr>
                                <td><?php echo $pro['PRO_NOM']; ?></td>
                                <td><?php echo $pro['VNP_QTD'].' x R$ '.tools::float_to_money($pro['VNP_VLR']/$pro['VNP_QTD']); ?></td>
                                <td><?php echo 'R$ '.tools::float_to_money($pro['VNP_VLR']); ?></td>

                                <td>
                                    <input type="hidden" name="PRO_ID[]" value="">
                                    <input type="hidden" name="PRO_VLRVND[]" value="">
                                    <input type="hidden" name="PRO_VLRVNDTOT[]" value="">
                                    <input type="hidden" name="PRO_QTD[]" value="'">
                                </td>

                            </tr>
                        <?php } ?>
                </tbody>
            </table>
        </div>

        <div class="form-group">
            <dt><label>Cliente</label></dt>   
            <dd> 
                <?php
                $query = 'SELECT SQL_CACHE CLI_ID,CLI_NOM FROM CLIENTES WHERE CLI_STA = 1 ORDER BY CLI_NOM ASC';
                $rows = $this->db->fetchAll($query);

                $html = '<select id="CLI_ID" name="CLI_ID" class="form-control" ' . $disabled . '>';
                $html .= '<option value="">Nenhum</option>';
                foreach ($rows as $r) {
                    $select = $this->data['CLI_ID'] == $r['CLI_ID'] ? 'selected' : '';
                    $html .= '<option ' . $select . ' value="' . $r['CLI_ID'] . '">' . $r['CLI_NOM'] . '</option>';
                }
                $html .= '</select>';
                echo $html;
                ?>
            </dd>
        </div>

        <div class="form-group">
            <dt><label>Subtotal (R$)</label></dt>
            <dd> 
                <input type="text" id="VND_VLRSUB" class="form-control" value="<?php echo $this->data['VND_VLR'] + $this->data['VND_VLRDSC']; ?>" readonly="">
            </dd>
        </div>

        <div class="form-group">
            <dt><label>Desconto (R$)</label></dt>
            <dd> 
                <input type="text" id="VND_VLRDSC" name="VND_VLRDSC" class="form-control valor_pre2" value="<?php echo $this->data['VND_VLRDSC']; ?>" <?php echo $readonly; ?> >
            </dd>
        </div>

        <div class="form-group">
            <dt><label>TOTAL (R$)</label></dt>
            <dd> 
                <input type="text" id="VND_VLR" name="VND_VLR" class="form-control required" value="<?php echo $this->data['VND_VLR']; ?>" readonly="">
            </dd>
        </div>
        
        <div class="form-group">
            <dt><label>Meio de pagamento</label></dt>   
            <dd> 
                <?php
                $query = 'SELECT SQL_CACHE TMP_ID,TMP_NOM FROM TIPO_MEIOPAGAMENTO WHERE TMP_STA = 1 ORDER BY TMP_ID ASC';
                $rows = $this->db->fetchAll($query);

                $html = '<select id="TMP_ID" name="TMP_ID" class="form-control required" ' . $disabled . '>';
                $html .= '<option value="">Nenhum</option>';
                foreach ($rows as $r) {
                    $select = $this->data['TMP_ID'] == $r['TMP_ID'] ? 'selected' : '';
                    $html .= '<option ' . $select . ' value="' . $r['TMP_ID'] . '">' . $r['TMP_NOM'] . '</option>';
                }
                $html .= '</select>';
                echo $html;
                ?>
            </dd>
        </div>

        <div class="form-group">
            <dt><label>Observação</label></dt>
            <dd> 
                <textarea id="VND_OBS" name="VND_OBS" class="form-control" <?php echo $readonly; ?>><?php echo $this->data['VND_OBS']; ?></textarea>
            </dd>
        </div>

        <div class="form-group">
<?php if ($this->data['VND_ID'] <= 0) { ?>
                <button type="button" class="btn btn-lg btn-success submit">
                    <span class="glyphicon glyphicon-floppy-saved" aria-hidden="true"></span> 
                    Salvar
                </button>
<?php } ?>
            <a href="<?php echo $this->url(array('controller' => $this->controller, 'action' => 'index', 'id' => '')); ?>" class="btn btn-lg btn-danger">
                <span class="glyphicon glyphicon-floppy-remove" aria-hidden="true"></span> 
                Cancelar
            </a>
        </div>

    </div>
</form>

<?php if ($this->data['VND_ID'] <= 0) { ?>
<script>
    verfchcaixa();
</script>
<?php } ?>

<div class="modal fade" id="AbrirCaixaModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="exampleModalLabel">Abrir Caixa</h4>
            </div>
            <div class="modal-body">
                <form role="form">
                    <div class="form-group">
                        <label for="recipient-name" class="control-label">Saldo Inicial:</label>
                        <input type="text" class="form-control valor_pre2" id="vlr_ini">
                    </div>
                    <div class="form-group">
                        <label for="message-text" class="control-label">Observação:</label>
                        <textarea class="form-control" id="message-text" id="obs_ini"></textarea>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                <button type="button" class="btn btn-primary btn-abrir-caixa">Abrir Caixa</button>
            </div>
        </div>
    </div>
</div>
    
<div class="modal fade" id="FecharCaixaModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="exampleModalLabel">Fechamento do Caixa</h4>
            </div>
            <div class="modal-body">
                <form role="form">
                    <div class="form-group">
                        <label for="recipient-name" class="control-label">Saldo final:</label>
                        <input type="text" class="form-control valor_pre2" id="vlr_fim">
                    </div>
                    <div class="form-group">
                        <label for="message-text" class="control-label">Observação:</label>
                        <textarea class="form-control" id="message-text" id="obs_fim"></textarea>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                <button type="button" class="btn btn-primary btn-fechar-caixa">Fechar Caixa</button>
            </div>
        </div>
    </div>
</div>